//
//  StatusCellTopView.swift
//  Weibo8023
//
//  Created by styshy on 15/12/11.
//  Copyright © 2015年 sz. All rights reserved.
//

import UIKit

class StatusCellTopView: UIView {
    
    var viewModel:StatusViewModel?{
        didSet{
            iconView.sd_setImageWithURL(viewModel!.userProfileUrl, placeholderImage: viewModel!.userDefautlIconView)
            nameLabel.text = viewModel?.status.user?.screen_name
            memeberIconView.image = viewModel?.userMemberImage
            vipIconView.image = viewModel?.userVipImage
            timeLabel.text = viewModel?.createAt
            sourceLabel.text = viewModel?.status.source
        }
    }

    
    // MAKR: - 构造函数
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        setupUI()
    }


    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    /// 头像
    private lazy var iconView:UIImageView = UIImageView(imageName: "avatar_default_big")
    
    /// 昵称
    private lazy var nameLabel:UILabel = UILabel(title: "王老五", fontSize:14)
    
    /// 会员等级
    private lazy var memeberIconView:UIImageView = UIImageView(imageName: "common_icon_membership_level1")
    
    /// 认证图标
    private lazy var vipIconView:UIImageView = UIImageView(imageName: "avatar_vip")
    
    /// 时间标签
    private lazy var timeLabel: UILabel = UILabel(title: "现在", fontSize: 11, color: UIColor.orangeColor())
    
    /// 来源标签
    private lazy var sourceLabel:UILabel = UILabel(title: "黑马官网")

}

extension StatusCellTopView{
    private func setupUI(){
        
        let sepView:UIView = UIView()
        sepView.backgroundColor = UIColor.darkGrayColor()
        
        addSubview(sepView)
        addSubview(iconView)
        addSubview(nameLabel)
        addSubview(memeberIconView)
        addSubview(vipIconView)
        addSubview(timeLabel)
        addSubview(sourceLabel)
        
        // MARK:- 设置自动布局
        
        /// 0.设置
        sepView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(self.snp_top)
            make.left.equalTo(self.snp_left)
            make.right.equalTo(self.snp_right)
            make.height.equalTo(StatusCellMargin)
        }
        
        /// 1.头像
        iconView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(sepView.snp_bottom).offset(StatusCellMargin)
            make.left.equalTo(sepView.snp_left).offset(StatusCellMargin)
            make.width.height.equalTo(StatusCellIconWidth)
        }
        /// 2.昵称
        nameLabel.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(iconView.snp_top)
            make.left.equalTo(iconView.snp_right).offset(StatusCellMargin)
        }
        //  3.等级
        memeberIconView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(nameLabel.snp_top)
            make.left.equalTo(nameLabel.snp_right).offset(StatusCellMargin)
        }
        
        /// 4.认证
        vipIconView.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(iconView.snp_right)
            make.centerY.equalTo(iconView.snp_bottom)
        }
        
        /// 5.时间标签
        timeLabel.snp_makeConstraints { (make) -> Void in
            make.bottom.equalTo(iconView.snp_bottom)
            make.left.equalTo(iconView.snp_right).offset(StatusCellMargin)
        }
        
        /// 6.来源
        sourceLabel.snp_makeConstraints { (make) -> Void in
            make.left.equalTo(timeLabel.snp_right).offset(StatusCellMargin)
            make.top.equalTo(timeLabel.snp_top)
        }
    }
}
